package com.yssw.client.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yssw.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yssw.common.annotation.Log;
import com.yssw.common.core.controller.BaseController;
import com.yssw.common.core.domain.AjaxResult;
import com.yssw.common.enums.BusinessType;
import com.yssw.client.domain.CheckReport;
import com.yssw.client.service.ICheckReportService;
import com.yssw.common.utils.poi.ExcelUtil;
import com.yssw.common.core.page.TableDataInfo;

/**
 * 检查报告Controller
 *
 * @author yssw
 * @date 2023-04-01
 */
@Anonymous
@RestController
@RequestMapping("/client/report")
public class CheckReportController extends BaseController {
    @Autowired
    private ICheckReportService checkReportService;

    /**
     * 查询检查报告列表
     */
//    @PreAuthorize("@ss.hasPermi('client:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckReport checkReport) {
        startPage();
        List<CheckReport> list = checkReportService.selectCheckReportList(checkReport);
        return getDataTable(list);
    }

    /**
     * 导出检查报告列表
     */
//    @PreAuthorize("@ss.hasPermi('client:report:export')")
    @Log(title = "检查报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckReport checkReport) {
        List<CheckReport> list = checkReportService.selectCheckReportList(checkReport);
        ExcelUtil<CheckReport> util = new ExcelUtil<CheckReport>(CheckReport.class);
        util.exportExcel(response, list, "检查报告数据");
    }

    /**
     * 获取检查报告详细信息
     */
//    @PreAuthorize("@ss.hasPermi('client:report:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(checkReportService.selectCheckReportById(id));
    }

    /**
     * 新增检查报告
     */
    @PreAuthorize("@ss.hasPermi('client:report:add')")
    @Log(title = "检查报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckReport checkReport) {
        return toAjax(checkReportService.insertCheckReport(checkReport));
    }

    /**
     * 修改检查报告
     */
    @PreAuthorize("@ss.hasPermi('client:report:edit')")
    @Log(title = "检查报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckReport checkReport) {
        return toAjax(checkReportService.updateCheckReport(checkReport));
    }

    /**
     * 删除检查报告
     */
    @PreAuthorize("@ss.hasPermi('client:report:remove')")
    @Log(title = "检查报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(checkReportService.deleteCheckReportByIds(ids));
    }
}
